package com.ruoyi.teaching.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.core.utils.ServletUtils;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.model.LoginUser;
import com.ruoyi.teaching.api.domain.CurriculumDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.teaching.domain.Curriculum;
import com.ruoyi.teaching.service.ICurriculumService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 课表 管理Controller
 * 
 * @author myh
 * @date 2024-03-25
 */
@RestController
@RequestMapping("/curriculum")
public class CurriculumController extends BaseController
{
    @Autowired
    private ICurriculumService curriculumService;

    /**
     * 查询课表 管理列表
     */
    @RequiresPermissions("teaching:curriculum:list")
    @GetMapping("/list")
    public TableDataInfo list(Curriculum curriculum)
    {
        startPage();
        List<Curriculum> list = curriculumService.selectCurriculumList(curriculum);
        return getDataTable(list);
    }

    @PostMapping("/getList")
    public AjaxResult getList(@RequestBody CurriculumDto curriculumDto)
    {
        Curriculum curriculum = BeanUtil.copyProperties(curriculumDto, Curriculum.class);
        List<Curriculum> list = curriculumService.selectCurriculumList(curriculum);
        return success(list);
    }

    /**
     * 导出课表 管理列表
     */
    @RequiresPermissions("teaching:curriculum:export")
    @Log(title = "课表 管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Curriculum curriculum)
    {
        List<Curriculum> list = curriculumService.selectCurriculumList(curriculum);
        ExcelUtil<Curriculum> util = new ExcelUtil<Curriculum>(Curriculum.class);
        util.exportExcel(response, list, "课表 管理数据");
    }

    /**
     * 获取课表 管理详细信息
     */
    @RequiresPermissions("teaching:curriculum:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(curriculumService.selectCurriculumById(id));
    }
    /**
     * 获取课表 管理详细信息
     */
    @RequiresPermissions("teaching:curriculum:query")
    @GetMapping(value = "/getCurriculumList")
    public AjaxResult getCurriculumList()
    {
        return success(curriculumService.getCurriculumList());
    }



    /**
     * 新增课表 管理
     */
    @RequiresPermissions("teaching:curriculum:add")
    @Log(title = "课表 管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Curriculum curriculum)
    {
        return toAjax(curriculumService.insertCurriculum(curriculum));
    }

    /**
     * 修改课表 管理
     */
    @RequiresPermissions("teaching:curriculum:edit")
    @Log(title = "课表 管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Curriculum curriculum)
    {
        return toAjax(curriculumService.updateCurriculum(curriculum));
    }

    /**
     * 删除课表 管理
     */
    @RequiresPermissions("teaching:curriculum:remove")
    @Log(title = "课表 管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(curriculumService.deleteCurriculumByIds(ids));
    }

    @Log(title = "用户管理", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<Curriculum> util = new ExcelUtil<Curriculum>(Curriculum.class);
        List<Curriculum> curriculumList = util.importExcel(file.getInputStream());
        return toAjax(curriculumService.importCurriculum(curriculumList, updateSupport));
    }
}
